[SUBROUTINE]
version = 1.14
name = _("Drill Array")
icon = drill-array.png
type = drill-array
help = _("<b>Drill Lines of Holes</b>")
order = act fcut h1 x al_x y al_y h2 xc dx dxdef yc dy dydef h4 rot h3 s u_s ugc dpt u_dpt ugcd

[PARAM_ACT]
name = _("Active")
icon = enable.png
type = bool
value = 1

[PARAM_FCUT]
name = _("Show design")
icon = glasses.png
type = bool
value = 1

[PARAM_H1]
name = _("Coords")
type = sub-header

[PARAM_H2]
type = sub-header
name = _("Size and offsets")

[PARAM_H4]
name = _("Rotation")
type = sub-header

[PARAM_H3]
name = _("Drilling")
type = sub-header

[PARAM_X]
name = _("X")
type = float
icon = x.png
tool_tip = _("X reference")
value = 0
metric_value = 0.0
header = h1

[PARAM_AL_X]
name = _("Align axis")
type = combo
options = _("Left=0:Center=1:Right=2")
header = h1
icon = align-x.png
value = 1
tool_tip = _("Define X reference point")

[PARAM_XC]
name = _("X axis count")
type = int
minimum_value = 1
icon = copies-holes.png
tool_tip = _("Number of holes")
value = 2
header = h2

[PARAM_Y]
name = _("Y")
type = float
icon = y.png
tool_tip = _("Y reference")
value = 0
metric_value = 0.0
header = h1

[PARAM_AL_Y]
name = _("Align axis")
type = combo
options = _("Top=0:Center=1:Bottom=2")
icon = align-y.png
header = h1
value = 1
tool_tip = _("Define Y reference point")

[PARAM_YC]
name = _("Y axis count")
type = int
minimum_value = 1
icon = copies-holes.png
tool_tip = _("Number of holes")
value = 2
header = h2

[PARAM_DX]
name = _("dX")
type = float
icon = dx.png
tool_tip = _("X offset")
value = 1
metric_value = 30
header = h2

[PARAM_DXDEF]
name = _("dX options")
type = combo
options = _("Between each hole=0:Overall=1")
header = h2
icon = len-opt-x.png
value = 0
tool_tip = _("Define dX")

[PARAM_DYDEF]
name = _("dY options")
type = combo
options = _("Between each hole=0:Overall=1")
header = h2
icon = len-opt-y.png
value = 0
tool_tip = _("Define dY")

[PARAM_DY]
name = _("dY")
type = float
icon = dy.png
tool_tip = _("Y offset")
value = 0.5
metric_value = 12
header = h2

[PARAM_ROT]
name = _("Angle")
type = float
digits = 2
icon = angle.png
tool_tip = _("Rotation of line")
value = 0.00
header = h4
suffix = &#176;

[PARAM_S]
name = _("Drill start")
type = combo-user
options = _("User defined=0:Surface=1:Half=2:One quarter=3:Three quarter=4:G-Code=5")
icon = drill-start.png
tool_tip = _("Pre or user defined")
value = 1
header = h3
links = u_s=0:ugc=5

[PARAM_U_S]
name = _("User start")
type = float
value = 0.0
metric_value = 0.0
header = h3
hidden = 1

[PARAM_UGC]
name = User gcode
type = gcode
value = 
header = h3
hidden = 1

[PARAM_UGCD]
name = User depth gcode
type = gcode
value =
header = h3
hidden = 1

[PARAM_DPT]
name = _("Drill down to")
type = combo-user
options = _("User defined=0:Through=1:Center drill depth=2:Bottom=3:Half=4:One quarter=5:Three quarter=6:G-Code=7")
icon = drill-end.png
tool_tip = _("Pre or user defined")
value = 1
header = h3
links = u_dpt=0:ugcd=7

[PARAM_U_DPT]
name = _("User depth")
type = float
value = 0.0
metric_value = 0.0
header = h3
hidden = 1

[DEFINITIONS]
content =
;	<eval>self.include_once(file name here)</eval>

[CALL]
content =
	(begin #sub_name)
	(drill #param_xc by #param_yc holes author : Fernand Veilleux)
	
	o<#self_id_active> if [#param_act AND [#<_tool_usage> EQ 3]] (if active)
		o<select> CALL [31] [#param_s] [#param_u_s] [#<surface>] [#<surface> - #<wp_depth> / 2] [#<surface> - #<wp_depth> / 4] [#<bottom> + #<wp_depth> / 4] [#param_ugc]
		o<select> CALL [32] [#param_dpt] [#param_u_dpt] [#<bottom_through>] [#31 + #<center_drill_depth>] [#<bottom>] [#<surface> - #<wp_depth> / 2] [#<surface> - #<wp_depth> / 4] [#<bottom> + #<wp_depth> / 4] [#param_ugcd]
		
		o<#self_id_01> if [#param_xc EQ 1]
			#33 = 0
		o<#self_id_01> else
			o<select> CALL [33] [#param_dxdef] [#param_dx] [#param_dx / [#param_xc - 1]]
		o<#self_id_01> endif
		#<dx#ID> = #33
		o<select> CALL [33] [#param_al_x] [0] [- [#param_xc - 1] * #<dx#ID> / 2] [- [#param_xc - 1] * #<dx#ID>]
		#<first_x#ID> = #33
		
		o<#self_id_02> if [#param_yc EQ 1]
			#33 = 0
		o<#self_id_02> else
			o<select> CALL [33] [#param_dydef] [#param_dy] [#param_dy / [#param_yc - 1]]
		o<#self_id_02> endif
		#<dy#ID> = #33
		o<select> CALL [33] [#param_al_y] [- #<dy#ID> * [#param_yc - 1]] [- #<dy#ID> * [#param_yc - 1] / 2] [0]
		#<first_y#ID> = #33
		
		(get and save current coords system offsets)
		#<old_coord_system#ID> = [#<_coord_system> / 10]
		o<get_offsets> CALL
		#<offset_x#ID> = #<_offsets_x>
		#<offset_y#ID> = #<_offsets_y>
		#<offset_z#ID> = #<_offsets_z>
		#<offset_r#ID> = #<_offsets_r>

		(change coords system)
		G#<_off_rot_coord_system>
	
		o<set_spindle_rpm> CALL [#<_drill_rpm>] [#<_drill_feed>]
		#<start_y#ID> = [#<offset_y#ID> + #<first_y#ID>]
		#<x_step#ID>  = 1
		#<x_round#ID> = 0
		#<start_x#ID> = [#<offset_x#ID> + #<first_x#ID>]
		
		o<#self_id_loop_Y> repeat [#param_yc]
			o<#self_id_loop_X> repeat [#param_xc]
				(get rotated coordinates then apply to new coords)
				o<rotate_xy> CALL [#<start_x#ID> + #param_x] [#<start_y#ID> + #param_y] [#<offset_x#ID> + #param_x] [#<offset_y#ID> + #param_y] [#<offset_r#ID> + #param_rot]
				G10 L2 P#5220 X[#<_rotated_x>] Y[#<_rotated_y>] Z#<offset_z#ID> R[#<offset_r#ID> + #param_rot]
				
				o<drill_single> CALL [0] [0] [#31] [#32] [#<drill_diameter>] [#<drill_point_len>] [#param_fcut]
		
				#<x_round#ID> = [#<x_round#ID> + #<x_step#ID>]
				o<#self_id_inc> if [[#<x_round#ID> LT #param_xc] AND [#<x_round#ID> GT 0]]
					#<start_x#ID>  = [#<start_x#ID>  + #<dx#ID> * #<x_step#ID>]
				o<#self_id_inc> endif
			o<#self_id_loop_X> endrepeat
	
			#<x_step#ID>  = [#<x_step#ID>   * -1]
			#<start_y#ID> = [#<start_y#ID> + #<dy#ID>]
		o<#self_id_loop_Y> endrepeat
	
		o<#self_id_stop> if [#<_spindle_all_time> EQ 0]
			M9 M5
		o<#self_id_stop> endif
	
		(restore coordinate system)
		G#<old_coord_system#ID>
		G10 L2 P#5220 X#<offset_x#ID> Y#<offset_y#ID> Z#<offset_z#ID> R#<offset_r#ID>
	
	o<#self_id_active> endif
	(end #sub_name)
